if (NOT DEFINED KDIR)
	set(KDIR "/usr/src/linux")
endif (NOT DEFINED KDIR)

ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/driver/pptp.ko
	COMMAND rm -rf ${CMAKE_CURRENT_BINARY_DIR}/driver
	COMMAND mkdir ${CMAKE_CURRENT_BINARY_DIR}/driver
	COMMAND ln -sf ${CMAKE_CURRENT_SOURCE_DIR}/* ${CMAKE_CURRENT_BINARY_DIR}/driver
	COMMAND make -C ${KDIR} M=${CMAKE_CURRENT_BINARY_DIR}/driver modules
	DEPENDS pptp.c
)

ADD_CUSTOM_TARGET(pptp_drv ALL
	DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/driver/pptp.ko
)

IF (NOT DEFINED CPACK_TYPE)
	INSTALL(CODE "EXECUTE_PROCESS(COMMAND make -C ${KDIR} M=${CMAKE_CURRENT_BINARY_DIR}/driver modules_install)")
ENDIF (NOT DEFINED CPACK_TYPE)
